package com.RPGDice.util;

import com.criticalritrpg.R;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Roll {
	
	private static Random rGenerator = new Random();
	
	public static List<RollSet> rollDices (){
		List<RollSet> rollSet = new ArrayList<RollSet>();
		
		int[] dicesNum = Settings.getNumberOfDices();
		int numOfRolls = Settings.getNumOfRolls();
		
		for (int i = 0; i < numOfRolls; i++){
			RollSet dices = new RollSet(i);
			for (int j = 0; j < dicesNum.length; j++){
				if ( dicesNum[j] != 0){
					RollableDice newDice = new RollableDice(Dices.DICES_NAME[j], dicesNum[j], Dices.DICES_COLOR[j]);
					for (int k = 0; k < dicesNum[j]; k++){
						
						int throwResult = throwDice(Dices.DICES_MIN_VALUE[j], Dices.DICES_MAX_VALUE[j]);
						newDice.addRollValue(throwResult);
						System.out.println("Roll num: " + i + " - " + Dices.DICES_NAME[j] + ": dice# " + k + " result: " + throwResult);
						
					}
					dices.addRollableDice(newDice);
				}
			}
			rollSet.add(dices);
		}
		
		
		
		
		/*for (int i = 0; i < dicesNum.length; i++){
			if (dicesNum[i] > 0) {
				RollableDice newDice = new RollableDice(Dices.DICES_NAME[i], numOfRolls, Dices.DICES_COLOR[i]);
				for (int j = 0; j < numOfRolls; j++){
					for (int k = 0; k < dicesNum[i]; k++){
					int throwResult = throwDice(Dices.DICES_MIN_VALUE[i], Dices.DICES_MAX_VALUE[i]);
					newDice.addRollValue(throwResult);
					System.out.println("Roll num: " + j + " - " + newDice.getDiceName() + ": " + k + " result: " + throwResult);
					}
				}
				newDice.calculateResult();
				dices.add(newDice);
			}
		}*/
		return rollSet;
	}
	
	private static int throwDice(int minVal, int maxVal){
		int range = maxVal - minVal;
		return (rGenerator.nextInt(range+1)) + minVal;
	}

}
